package com.ls.mq.manager;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import com.ls.mq.actor.impl.DefaultMQFuture;
import com.ls.mq.iterface.IMQFuture;

public class FutureManager {

	private static FutureManager instance = new FutureManager();

	public static FutureManager getInstance() {
		return instance;
	}

	private FutureManager() {
	};

	private Map<String, IMQFuture> futureMap = new HashMap<>();

	public IMQFuture addFuture(String uuid) {
		return addFuture(uuid, 3 * 1000);
	}

	public IMQFuture addFuture(String uuid, int timeout) {
		return addFuture(uuid, new DefaultMQFuture(timeout, TimeUnit.MILLISECONDS));
	}

	public IMQFuture addFuture(String uuid, IMQFuture future) {
		futureMap.put(uuid, future);
		return future;
	}

	public IMQFuture getFuture(String uuid) {
		return futureMap.get(uuid);
	}

	public void removeFuture(String uuid) {
		futureMap.remove(uuid);
	}

}
